<template>
  <div class="ly-consul">
    <div class="ly-add-class">
      <el-button type="primary" @click="getAddConsult">新增新闻</el-button>
    </div>
    <div class="ly-table">
      <el-table :data="tableData" style="width: 100%" border>
        <el-table-column fixed prop="id" label="序号" width="100"></el-table-column>
        <el-table-column prop="title" label="标题" width="220"></el-table-column>
        <el-table-column prop="type" label="类型" width="120"></el-table-column>
        <el-table-column prop="serviceUrl" label="图片" width="220">
          <template slot-scope="scope">
            <img class="ly-img" :src="tableData[scope.$index].picture">
          </template>
        </el-table-column>
        <el-table-column prop="remark" label="简介"></el-table-column>
        <el-table-column fixed="right" label="操作" width="160">
          <template slot-scope="scope">
            <el-button type="primary" size="small" @click="getEdit(tableData[scope.$index])">编辑</el-button>
            <el-button size="small" @click="getDelete(tableData[scope.$index].id)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <listPage :pageData="pageList" v-if="pageList.totalRecNum >  pageList.pageSize" @getdata="setPageNo"></listPage>
  </div>
</template>


<script>
  import {findAll, deleteId} from '@/api/news'

  export default {
    data() {
      return {
        isRelease: true,
        codeContent: {}, // 弹窗内容
        pageList: {
          page: 1, //当前页
          totalRecNum: 0,   //总页数
          pageSize: 25  // 分页条数
        }, // 分页
        tableData: []
      }
    },
    watch: {
      $route() {
        this.findAllService()
      }
    },
    methods: {
      findAllService() {
        findAll().then(response => {
          let result = response.data
          if (result.code === '0000') {
            this.tableData = result.data
          }
        })
      },
      // 删除
      getDelete(data) {
        deleteId(data).then(response => {
          let result = response.data
          if (result.code === '0000') {
            this.$message.success(result.msg)
            this.findAllService()
          } else {
            this.$message.error(result.msg)
          }
        })
      },
      getEdit(data){
        this.$store.commit('updateEditInfoData', JSON.stringify(data))
        this.$router.push({path:'/news_add',query:{type:'edit'}})
      },
      // 新增 服务
      getAddConsult() {
        this.$router.push({path: '/news_add', query: {id: this.$route.query.id}})
      }
    },
    created() {
      this.findAllService()
    }
  }
</script>

<style scoped lang="scss">

</style>